# -*- coding:utf-8 -*-
# @Time : 21-7-26 上午11:33 
# @Author : zdy
# @File : VoltSignal.py
# desc:
import shelve
import pickle
from importQT import *
import copy
import os, datetime
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, DateTime, REAL, BLOB, and_
from Class.Factor import Factor


class VoltSignal(object):
    def __init__(self):
        self.result = DBResult()
        self.__lineData = DBLineData()
        self._dataTime = []
        self._dataChannel = [[], [], [], []]
        self.average = [0.0 for x in range(dataBase.maxChannel)]# 释放曲线开始时的基线均值
        self.factors = [Factor(), Factor(), Factor(), Factor()]
        # 记录实验时，通道的开启情况,非最终结果
        self.channels = []
        self._dataChannelDelay = [[], [], [], []]  # 记录积分延迟曲线（未减均值）
        self._averageVs = [0.0 for x in range(dataBase.maxChannel)]  # 原始信号基准电压，用于将调零信号转换为原始信号
        self.average0 = [0.0 for x in range(dataBase.maxChannel)]# 0浓度点的标准基线均值，只用于ONH，记录等待前的基线

    @property
    def DataChannelDelay(self):
        return self._dataChannelDelay

    @property
    def AverageVs(self):
        """原始信号基准电压，用于将调零信号转换为原始信号"""
        return self._averageVs

    @property
    def Results0(self):
        return [self.result.Content10, self.result.Content20, self.result.Content30, self.result.Content40]

    @Results0.setter
    def Results0(self, value):
        self.result.Content10 = value[0]
        self.result.Content20 = value[1]
        self.result.Content30 = value[2]
        self.result.Content40 = value[3]

    @property
    def sampleName(self):
        return self.result.SampleName

    @sampleName.setter
    def sampleName(self, name):
        self.result.SampleName = name

    @property
    def sampleNum(self):
        return self.result.SampleNum

    @sampleNum.setter
    def sampleNum(self, num):
        self.result.SampleNum = num

    @property
    def sampleWeight(self):
        return self.result.SampleWeight

    @sampleWeight.setter
    def sampleWeight(self, weight):
        self.result.SampleWeight = weight

    @property
    def fluxWeight(self):
        return self.result.FluxWeight

    @fluxWeight.setter
    def fluxWeight(self, weight):
        self.result.FluxWeight = weight

    @property
    def methodName(self):
        return self.result.MethodName

    @methodName.setter
    def methodName(self, name):
        self.result.MethodName = name

    @property
    def userName(self):
        return self.result.UserName

    @userName.setter
    def userName(self, name):
        self.result.UserName = name

    def addT(self, t):
        """添加时间"""
        self._dataTime.append(t)

    def addValue(self, i, v):
        """添加曲线"""
        self._dataChannel[i].append(v)

    def addValueDelay(self, i, v):
        """添加积分延迟内的曲线"""
        self._dataChannelDelay[i].append(v)

    def setaverageV(self, i, v):
        """设置原始信号基准电压"""
        self._averageVs[i] = v

    @property
    def sampleId(self):
        return self.result.SampleId

    @sampleId.setter
    def sampleId(self, id):
        str = id.strftime("%Y-%m-%d %H:%M:%S")
        time = datetime.datetime.strptime(str, "%Y-%m-%d %H:%M:%S")
        self.result.SampleId = time
        self.__lineData.SampleId = time

    @property
    def listData(self):
        return self._dataChannel

    def addListData(self, i, v):
        '''临时，测试用'''
        self._dataChannel[i].append(v)

    def getlistDataDelay(self, i):
        """
        获取带有积分延迟部分的释放曲线（都减去了积分均值）
        :param i: 通道
        :return: 曲线
        """
        listDataDelay = copy.copy(self.listData[i])  # 浅拷贝
        for index, delayV in enumerate(self._dataChannelDelay[i]):
            listDataDelay[index] = delayV - self.average[i]
        return listDataDelay

    def getlistDataInitial(self, i):
        """
        获取原始信号
        :param i: 通道
        :return: 曲线
        """
        listDataDelay = self.getlistDataDelay(i)
        listDataDelay = list(map(lambda x: x + self.average[i], listDataDelay))  # 加上积分延迟均值，得到原始的调零信号
        magnify = False
        if i > 1:
            magnify = True
        initialVs = Factor.convertToInitialVs(self._averageVs[i], listDataDelay, magnify)
        return initialVs

    @property
    def listT(self):
        return self._dataTime

    def addListT(self, v):
        '''临时，测试用'''
        self._dataTime.append(v)

    def addAll(self):
        '''添加结果和曲线数据到数据库'''
        if dataBase.addResult(self.result) and self.__addLineData():
            return dataBase.addFilter(self.result)
        return False

    def __addLineData(self):
        self.__lineData.DataTime = pickle.dumps(self._dataTime)
        self.__lineData.DataChannel1 = pickle.dumps(self._dataChannel[0])
        self.__lineData.DataChannel2 = pickle.dumps(self._dataChannel[1])
        self.__lineData.DataChannel3 = pickle.dumps(self._dataChannel[2])
        self.__lineData.DataChannel4 = pickle.dumps(self._dataChannel[3])
        self.__lineData.DataChannelDelay1 = pickle.dumps(self._dataChannelDelay[0])
        self.__lineData.DataChannelDelay2 = pickle.dumps(self._dataChannelDelay[1])
        self.__lineData.DataChannelDelay3 = pickle.dumps(self._dataChannelDelay[2])
        self.__lineData.DataChannelDelay4 = pickle.dumps(self._dataChannelDelay[3])
        self.__lineData.Channels = pickle.dumps((self.channels))
        self.__lineData.Factors = pickle.dumps(self.factors)
        self.__lineData.Averages = pickle.dumps(self.average)
        self.__lineData.AverageVs = pickle.dumps(self._averageVs)
        return dataBase.addLineData(self.__lineData)

    @staticmethod
    def loadAll(id):
        vs = VoltSignal()
        vs.result = dataBase.loadResult(id)
        vs.__lineData = dataBase.loadLineData(id)
        if vs.result == None or vs.__lineData == None:
            return None
        try:
            vs._dataTime = pickle.loads(vs.__lineData.DataTime)
            vs._dataChannel[0] = pickle.loads(vs.__lineData.DataChannel1)
            vs._dataChannel[1] = pickle.loads(vs.__lineData.DataChannel2)
            vs._dataChannel[2] = pickle.loads(vs.__lineData.DataChannel3)
            vs._dataChannel[3] = pickle.loads(vs.__lineData.DataChannel4)
            d1 = vs.__lineData.DataChannelDelay1
            if d1 is not None:
                vs._dataChannelDelay[0] = pickle.loads(d1)
            d2 = vs.__lineData.DataChannelDelay2
            if d2 is not None:
                vs._dataChannelDelay[1] = pickle.loads(d2)
            d3 = vs.__lineData.DataChannelDelay3
            if d3 is not None:
                vs._dataChannelDelay[2] = pickle.loads(d3)
            d4 = vs.__lineData.DataChannelDelay4
            if d4 is not None:
                vs._dataChannelDelay[3] = pickle.loads(d4)
            vs.channels = pickle.loads(vs.__lineData.Channels)
            vs.factors = pickle.loads(vs.__lineData.Factors)
            vs.average = pickle.loads(vs.__lineData.Averages)
            averageV = vs.__lineData.AverageVs
            if averageV is not None:
                vs._averageVs = pickle.loads(averageV)
            return vs
        except Exception as ex:
            print("Linedata反序列化失败")
            return  None

    @staticmethod
    def loadResult(id):
        return dataBase.loadResult(id)

    @staticmethod
    def updateResults(rs):
        """更新结果到数据库"""
        return dataBase.updateResults(rs)

    @staticmethod
    def updateSampleInfo(rs):
        """更新样品信息到数据库"""
        return dataBase.updateSampleInfo(rs)

    def calculateResult(self):
        self.result.Content1 = self.factors[0].calculateResult(self._dataTime, self._dataChannel[0],
                                                               self.result.SampleWeight, self.average[0],
                                                               self.result.FluxWeight)
        self.result.Content2 = self.factors[1].calculateResult(self._dataTime, self._dataChannel[1],
                                                               self.result.SampleWeight, self.average[1],
                                                               self.result.FluxWeight)
        self.result.Content3 = self.factors[2].calculateResult(self._dataTime, self._dataChannel[2],
                                                               self.result.SampleWeight, self.average[2],
                                                               self.result.FluxWeight)
        self.result.Content4 = self.factors[3].calculateResult(self._dataTime, self._dataChannel[3],
                                                               self.result.SampleWeight, self.average[3],
                                                               self.result.FluxWeight)
        self.result.Content10 = self.result.Content1
        self.result.Content20 = self.result.Content2
        self.result.Content30 = self.result.Content3
        self.result.Content40 = self.result.Content4
        # TODO
        self.result.Area1 = self.factors[0].calculateIntegral(self._dataTime, self._dataChannel[0])
        self.result.Area2 = self.factors[1].calculateIntegral(self._dataTime, self._dataChannel[1])
        self.result.Area3 = self.factors[2].calculateIntegral(self._dataTime, self._dataChannel[2])
        self.result.Area4 = self.factors[3].calculateIntegral(self._dataTime, self._dataChannel[3])

        if self.result.Channel & 0x02 == 0x02:
            self.result.Content01 = self.result.Content2
            self.result.Area01 = self.result.Area2
        else:
            self.result.Content01 = self.result.Content1
            self.result.Area01 = self.result.Area1
        if dataBase.devicetype:
            if self.result.Channel & 0x08 == 0x08:
                self.result.Content02 = self.result.Content4
                self.result.Area02 = self.result.Area4
            else:
                self.result.Content02 = self.result.Content3
                self.result.Area02 = self.result.Area3
        else:
            self.result.Content02 = self.result.Content3
            self.result.Area02 = self.result.Area3
            self.result.Content03 = self.result.Content4
            self.result.Area03 = self.result.Area4



# class Result(object):
#     def __init__(self):
#         self.SampleId = None
#         self.SampleName
#         self.SampleNum
#         self.SampleWeight
#         self.FluxWeight
#         self.Content01
#         self.Content02
#         self.Content03
#         self.Channel
#         self.Content1
#         self.Content2
#         self.Content3
#         self.Content4
#         self.Content5
#         self.Content6
#         self.Content10
#         self.Content20
#         self.Content30
#         self.Content40
#         self.Content50
#         self.Content60
#         self.MethodName
#         self.UserNam
#
# class LineData(object):
#     def __init__(self):
#         self.SampleId
#         self.Channels
#         self.Factors
#         self.Averages
#         self.LineFactor
#         self.DataChannel1
#         self.DataChannel2
#         self.DataChannel3
#         self.DataChannel4
#         self.DataChannel5
#         self.DataChannel6

class DataBase(object):
    def __init__(self):
        self.type = 0 # 0数据库；1文件
        self.resultPath:str
        self.dataPath:str
        self.filterPath:str
        self.session_factory = None
        self.maxChannel = 4
        self.datadb = QtSql.QSqlDatabase()


    def initType(self, datatype, deviceType):
        """
        初始化对象
        :param datatype: 数据存储方式 0数据库；1文件
        :param deviceType: 仪器类型，TrueCS FalseONH
        :return:
        """
        self.type = datatype  # 0数据库；1文件
        self.devicetype = deviceType    #True CS
        if self.devicetype:
            self.dbColId = ['时间', 0]
            self.dbColSampleName = ['样品名称', 1]
            self.dbColSampleNum = ['编号', 2]
            self.dbColSampleWeight = ['样品质量', 3]
            self.dbColFluxWeight = ['助熔剂质量', 4]
            self.dbColE1 = ['C', 5]
            self.dbColE2 = ['S', 6]
            self.dbColChannel = ['通道', 7]
            self.dbColLE1 = ['LC', 8]
            self.dbColHE1 = ['HC', 9]
            self.dbColLE2 = ['LS', 10]
            self.dbColHE2 = ['HS', 11]
            self.dbColReLE1 = ['校正后LC', 12]
            self.dbColReHE1 = ['校正后HC', 13]
            self.dbColReLE2 = ['校正后LS', 14]
            self.dbColReHE2 = ['校正后HS', 15]
            self.dbArea01 = ['C面积', 16]
            self.dbArea02 = ['S面积', 17]
            self.dbArea1 = ['LC面积', 18]
            self.dbArea2 = ['HC面积', 19]
            self.dbArea3 = ['LS面积', 20]
            self.dbArea4 = ['HS面积', 21]
            self.dbColMethod = ['方法', 22]
            self.dbColUser = ['用户名', 23]
            self.dbColNames = [self.dbColId[0], self.dbColSampleName[0], self.dbColSampleNum[0],
                               self.dbColSampleWeight[0],
                               self.dbColFluxWeight[0], self.dbColE1[0], self.dbColE2[0], self.dbColChannel[0],
                               self.dbColLE1[0], self.dbColHE1[0], self.dbColLE2[0], self.dbColHE2[0],
                               self.dbColReLE1[0], self.dbColReHE1[0], self.dbColReLE2[0], self.dbColReHE2[0],
                               self.dbArea01[0], self.dbArea02[0], self.dbArea1[0], self.dbArea2[0],
                               self.dbArea3[0], self.dbArea4[0], self.dbColMethod[0], self.dbColUser[0]]
            self.colresultNum = [self.dbColE1[1], self.dbColE2[1], self.dbColLE1[1], self.dbColHE1[1], self.dbColLE2[1],
                                 self.dbColHE2[1], self.dbColReLE1[1], self.dbColReHE1[1], self.dbColReLE2[1],
                                 self.dbColReHE2[1]]
            self.colareaNum = [self.dbArea01[1], self.dbArea02[1], self.dbArea1[1], self.dbArea2[1],
                               self.dbArea3[1], self.dbArea4[1]]
        else:
            self.dbColId = ['时间', 0]
            self.dbColSampleName = ['样品名称', 1]
            self.dbColSampleNum = ['编号', 2]
            self.dbColSampleWeight = ['样品质量', 3]
            self.dbColFluxWeight = ['助熔剂质量', 4]
            self.dbColE1 = ['O', 5]
            self.dbColE2 = ['N', 6]
            self.dbColE3 = ['H', 7]
            self.dbColChannel = ['通道', 8]
            self.dbColLE1 = ['LO', 9]
            self.dbColHE1 = ['HO', 10]
            self.dbColLE2 = ['N', 11]
            self.dbColLE3 = ['H', 12]
            self.dbColReLE1 = ['校正后LO', 13]
            self.dbColReHE1 = ['校正后HO', 14]
            self.dbColReLE2 = ['校正后N', 15]
            self.dbColReLE3 = ['校正后H', 16]
            self.dbArea01 = ['O面积', 17]
            self.dbArea02 = ['N面积', 18]
            self.dbArea03 = ['H面积', 19]
            self.dbArea1 = ['LO面积', 20]
            self.dbArea2 = ['HO面积', 21]
            self.dbArea3 = ['N面积', 22]
            self.dbArea4 = ['H面积', 23]
            self.dbColMethod = ['方法', 24]
            self.dbColUser = ['用户名', 25]
            self.dbColNames = [self.dbColId[0], self.dbColSampleName[0], self.dbColSampleNum[0], self.dbColSampleWeight[0],
                               self.dbColFluxWeight[0], self.dbColE1[0], self.dbColE2[0], self.dbColE3[0],
                               self.dbColChannel[0], self.dbColLE1[0], self.dbColHE1[0], self.dbColLE2[0], self.dbColLE3[0],
                               self.dbColReLE1[0], self.dbColReHE1[0], self.dbColReLE2[0], self.dbColReLE3[0],
                               self.dbArea01[0], self.dbArea02[0], self.dbArea03[0], self.dbArea1[0], self.dbArea2[0],
                               self.dbArea3[0], self.dbArea4[0], self.dbColMethod[0], self.dbColUser[0]]
            self.colresultNum = [self.dbColE1[1], self.dbColE2[1], self.dbColE3[1],self.dbColLE1[1],self.dbColHE1[1],
                                 self.dbColLE2[1],self.dbColLE3[1], self.dbColReLE1[1], self.dbColReHE1[1],
                                 self.dbColReLE2[1],self.dbColReLE3[1]]
            self.colareaNum = [self.dbArea01[1], self.dbArea02[1], self.dbArea03[1],self.dbArea1[1], self.dbArea2[1],
                               self.dbArea3[1], self.dbArea4[1]]
        self.colNum = len(self.dbColNames)
        self.colweightNum = [self.dbColSampleWeight[1], self.dbColFluxWeight[1]]

    def initDB(self, dbPath):
        if self.type ==0:
            dataPath = os.path.join(dbPath, "data.db")
            if not os.path.exists(dataPath):  # 文件不存在
                return False
            try:
                # engine = create_engine('sqlite:///cs/data.db?check_same_thread=False', echo=False)
                engine = create_engine('sqlite:///' + dataPath + '?check_same_thread=False', echo=False)
                self.session_factory = sessionmaker(bind=engine)
                # self.session = scoped_session(self.session_factory)
                return True
            except Exception as ex:
                print("数据库初始化异常：", ex)
                return False
            return False
        else:
            self.resultPath = os.path.join(dbPath, "result.dat")
            self.dataPath = os.path.join(dbPath, "data.dat")
            self.filterPath = os.path.join(dbPath, "filter.dat")
            return True

    def selectResults(self, start, end, name:str):
        """查询指定时间内的结果"""
        if self.type == 0:
            r = None
            try:
                session = self.session_factory()
                if start  is None and end is None:
                    r = session.query(DBResult).filter(DBResult.SampleName.like('%'+name+"%")).all()
                else:
                    r = session.query(DBResult).filter(DBResult.SampleId > start, DBResult.SampleId < end,
                                                       DBResult.SampleName.like('%'+name+"%")).all()

            except Exception as ex:
                print(ex)
                session.rollback()
                raise
            finally:
                session.close()
            return r
        else:
            r =[]
            filters = []
            with shelve.open(self.filterPath, flag='c', protocol=None, writeback=False) as f:
                filters = f["filter"]
            startIndex = -1
            endIndex = len(filters) - 1
            for i, filter in enumerate(filters):
                try:
                    date = datetime.datetime.strptime(filter, "%Y-%m-%d %H:%M:%S")
                    if date < start:
                        continue
                    if startIndex == -1:
                        startIndex = i
                    if date >end:
                        endIndex = i -1 if i-1>0 else 0
                        break
                except:
                    pass
            if startIndex > -1:
                with shelve.open(self.resultPath, flag='c', protocol=None, writeback=False) as s1:
                    for i in range(startIndex, endIndex+1):
                        if filters[i] in s1.keys():
                            res = s1[filters[i]]['DBResult']
                            r.append(res)
            return r

    def loadResult(self, id):
        if self.type ==0:
            r = None
            try:
                session = self.session_factory()
                if isinstance(id, str):
                    t = datetime.datetime.strptime(id, "%Y-%m-%d %H:%M:%S")
                else:
                    t = id
                r = session.query(DBResult).filter(DBResult.SampleId == t).first()
            except Exception as ex:
                print(ex)
                session.rollback()
                raise
            finally:
                session.close()
            return r
        else:
            r = None
            if isinstance(id, str):
                s = id
            else:
                s = id.strftime("%Y-%m-%d %H:%M:%S")
            with shelve.open(self.resultPath, flag='c', protocol=None, writeback=False) as s1:
                if s in s1.keys():
                    r = s1[s]['DBResult']
            return r

    def loadLineData(self, id):
        if self.type ==0:
            d = None
            try:
                session = self.session_factory()
                if isinstance(id, str):
                    t = datetime.datetime.strptime(id, "%Y-%m-%d %H:%M:%S")
                else:
                    t = id
                d = session.query(DBLineData).filter(DBLineData.SampleId == t).first()

            except Exception as ex:
                print(ex)
                session.rollback()
                raise
            finally:
                session.close()
            return d
        else:
            d = None
            if isinstance(id, str):
                s = id
            else:
                s = id.strftime("%Y-%m-%d %H:%M:%S")
            with shelve.open(self.dataPath, flag='c', protocol=None, writeback=False) as s1:
                if s in s1.keys():
                    d = s1[s]['DBLineData']
            return d

    def addResult(self, r):
        if self.type ==0:
            return self.addLineData(r)
        else:
            r: DBResult
            with shelve.open(self.resultPath, flag='c', protocol=None, writeback=False) as s1:
                s = r.SampleId.strftime("%Y-%m-%d %H:%M:%S")
                if s not in s1.keys():
                    s1[s] = {'DBResult':r}
                    return True
                else:
                    return False
            return False

    def addLineData(self, d):
        if self.type ==0:
            try:
                session = self.session_factory()
                session.add(d)
                session.commit()
                b = d in session  # True
                # 添加以下两句，保证session关闭后，d对象还可以使用
                session.refresh(d)
                session.expunge(d)
                return True
            except Exception as ex:
                print(ex)
                session.rollback()
                return False
                raise
            finally:
                session.close()  # d in session  False
        else:
            d: DBLineData
            with shelve.open(self.dataPath, flag='c', protocol=None, writeback=False) as s1:
                s = d.SampleId.strftime("%Y-%m-%d %H:%M:%S")
                if s not in s1.keys():
                    s1[s] = {'DBLineData':d}
                    return True
                else:
                    return False
            return False

    def addFilter(self, r):
        if self.type ==0:
            return True
        else:
            r: DBResult
            s1 = shelve.open(self.filterPath, flag='c', protocol=None, writeback=True)
            try:
                s = r.SampleId.strftime("%Y-%m-%d %H:%M:%S")
                filters = s1["filter"]
                filters.append(s)
                return True
            except:
                s1.close()
                return False

    def updateResults(self, rs):
        if self.type ==0:
            try:
                session = self.session_factory()
                for r in rs:
                    # 更新成功后，result = 1.否则为0
                    result = session.query(DBResult).filter_by(SampleId=r.SampleId).update({"Content10": r.Content10,
                                                                                            "Content20": r.Content20,
                                                                                            "Content30": r.Content30,
                                                                                            "Content40": r.Content40,
                                                                                            })
                    if result != 1:
                        session.commit()
                        return False
                session.commit()
                return True
            except Exception as ex:
                print(ex)
                session.rollback()
                return False
                raise
            finally:
                session.close()  # d in session  False
        else:
            return self.updateSampleInfo(rs)

    def updateSampleInfo(self, rs):
        if self.type ==0:
            try:
                session = self.session_factory()
                for r in rs:
                    # 更新成功后，result = 1.否则为0
                    r: DBResult
                    result = session.query(DBResult).filter_by(SampleId=r.SampleId).update({"SampleName": r.SampleName,
                                                                                            "SampleNum": r.SampleNum,
                                                                                            "SampleWeight": r.SampleWeight,
                                                                                            "FluxWeight": r.FluxWeight})
                    if result != 1:
                        session.commit()
                        return False
                session.commit()
                return True
            except Exception as ex:
                print(ex)
                session.rollback()
                return False
                raise
            finally:
                session.close()  # d in session  False
        else:
            res = True
            s1 = shelve.open(self.resultPath, flag='c', protocol=None, writeback=False)
            try:
                for r in rs:
                    r:DBResult
                    id = r.SampleId.strftime("%Y-%m-%d %H:%M:%S")
                    if id in s1.keys():
                        s1[id] ={'DBResult':r}
                    else:
                        res = False
                        break
            except:
                res = False
            finally:
                s1.close()
            return res

    def closeDB(self):
        pass

Base = declarative_base()


class DBResult(Base):
    __tablename__ = 'Result'
    SampleId = Column(DateTime, primary_key=True)
    SampleName = Column(String(50), default="")
    SampleNum = Column(String(20), default=0.0)
    SampleWeight = Column(REAL, default=0.0)
    FluxWeight = Column(REAL, default=0.0)
    Content01 = Column(REAL, default=0.0)
    Content02 = Column(REAL, default=0.0)
    Content03 = Column(REAL, default=0.0)
    Channel = Column(Integer, default=0)
    Content1 = Column(REAL, default=0.0)
    Content2 = Column(REAL, default=0.0)
    Content3 = Column(REAL, default=0.0)
    Content4 = Column(REAL, default=0.0)
    Content10 = Column(REAL, default=0.0)
    Content20 = Column(REAL, default=0.0)
    Content30 = Column(REAL, default=0.0)
    Content40 = Column(REAL, default=0.0)
    Area01 = Column(REAL, default=0.0)
    Area02 = Column(REAL, default=0.0)
    Area03 = Column(REAL, default=0.0)
    Area1 = Column(REAL, default=0.0)
    Area2 = Column(REAL, default=0.0)
    Area3 = Column(REAL, default=0.0)
    Area4 = Column(REAL, default=0.0)
    MethodName = Column(String(20), default="")
    UserName = Column(String(20), default="")


class DBLineData(Base):
    __tablename__ = 'Data'
    SampleId = Column(DateTime, primary_key=True)
    Channels = Column(BLOB)
    Factors = Column(BLOB)
    Averages = Column(BLOB)
    LineFactor = Column(REAL)
    DataTime = Column(BLOB)
    DataChannel1 = Column(BLOB)
    DataChannel2 = Column(BLOB)
    DataChannel3 = Column(BLOB)
    DataChannel4 = Column(BLOB)
    DataChannelDelay1 = Column(BLOB)
    DataChannelDelay2 = Column(BLOB)
    DataChannelDelay3 = Column(BLOB)
    DataChannelDelay4 = Column(BLOB)
    AverageVs = Column(BLOB)


dataBase = DataBase()

